package org.agora.games.bodybuilder.ui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * @author : Arash Bizhanzadeh <arash.bizhanzadeh@cbc.ca>
 *         Date: 12-01-08
 *         Time: 9:04 PM
 *         CBC.ca All rights reserved.
 */
public class Parameters extends JDialog {
    JTextField average;
    JTextField maximumCurvature ;
    MainForm f;

    public Parameters(Frame frame, boolean b, String av, String max) {
        super(frame, b);
        f = (MainForm) frame;
        setLayout(new BorderLayout());
        JPanel buttonPanel = new JPanel();
        buttonPanel.setLayout(new BoxLayout(buttonPanel,BoxLayout.X_AXIS));
        JButton okButton = new JButton("OK");
        JButton cancelButton = new JButton("Cancel");
        cancelButton.addActionListener(
                new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent actionEvent) {
                        dispose();
                    }
                }
        );
        buttonPanel.add(Box.createGlue());
        buttonPanel.add(cancelButton);
        buttonPanel.add(okButton);
        okButton.addActionListener( new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                f.setAverage(average.getText());
                f.setMaximumCurvature(maximumCurvature.getText());
                dispose();
            }
        });
        this.add(buttonPanel, BorderLayout.SOUTH);
        JPanel inputPanel = new JPanel();
        inputPanel.setLayout(new GridLayout(0,2));
        add(inputPanel,BorderLayout.CENTER);
        JLabel averageLabel = new JLabel("Average on Points:");

        inputPanel.add(averageLabel);
        average = new JTextField();
        average.setText(av);
        inputPanel.add(average);
        inputPanel.add(new JLabel("Maximum allowed curvature:"));
        maximumCurvature = new JTextField();
        maximumCurvature.setText(max);
        inputPanel.add(maximumCurvature);
        pack();
        setVisible(true);
    }
    
    public String getAverage(){
        return average.getText();
    }
    
    public String getMaximumCurvature(){
        return maximumCurvature.getText();
        
    }
}
